import { Injectable } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Routes } from '@angular/router';
import { JhiPaginationUtil, JhiResolvePagingParams } from 'ng-jhipster';
import { UserRouteAccessService } from 'app/core';
import { Observable, of } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { HdfsLog } from 'app/shared/model/hdfsutil/hdfs-log.model';
import { HdfsLogService } from './hdfs-log.service';
import { HdfsLogComponent } from './hdfs-log.component';
import { HdfsLogDetailComponent } from './hdfs-log-detail.component';
import { HdfsLogUpdateComponent } from './hdfs-log-update.component';
import { HdfsLogDeletePopupComponent } from './hdfs-log-delete-dialog.component';
import { IHdfsLog } from 'app/shared/model/hdfsutil/hdfs-log.model';

@Injectable({ providedIn: 'root' })
export class HdfsLogResolve implements Resolve<IHdfsLog> {
  constructor(private service: HdfsLogService) {}

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<HdfsLog> {
    const id = route.params['id'] ? route.params['id'] : null;
    if (id) {
      return this.service.find(id).pipe(
        filter((response: HttpResponse<HdfsLog>) => response.ok),
        map((hdfsLog: HttpResponse<HdfsLog>) => hdfsLog.body)
      );
    }
    return of(new HdfsLog());
  }
}

export const hdfsLogRoute: Routes = [
  {
    path: 'hdfs-log',
    component: HdfsLogComponent,
    resolve: {
      pagingParams: JhiResolvePagingParams
    },
    data: {
      authorities: ['ROLE_USER'],
      defaultSort: 'id,asc',
      pageTitle: 'hdfsutilApp.hdfsutilHdfsLog.home.title'
    },
    canActivate: [UserRouteAccessService]
  },
  {
    path: 'hdfs-log/:id/view',
    component: HdfsLogDetailComponent,
    resolve: {
      hdfsLog: HdfsLogResolve
    },
    data: {
      authorities: ['ROLE_USER'],
      pageTitle: 'hdfsutilApp.hdfsutilHdfsLog.home.title'
    },
    canActivate: [UserRouteAccessService]
  },
  {
    path: 'hdfs-log/new',
    component: HdfsLogUpdateComponent,
    resolve: {
      hdfsLog: HdfsLogResolve
    },
    data: {
      authorities: ['ROLE_USER'],
      pageTitle: 'hdfsutilApp.hdfsutilHdfsLog.home.title'
    },
    canActivate: [UserRouteAccessService]
  },
  {
    path: 'hdfs-log/:id/edit',
    component: HdfsLogUpdateComponent,
    resolve: {
      hdfsLog: HdfsLogResolve
    },
    data: {
      authorities: ['ROLE_USER'],
      pageTitle: 'hdfsutilApp.hdfsutilHdfsLog.home.title'
    },
    canActivate: [UserRouteAccessService]
  }
];

export const hdfsLogPopupRoute: Routes = [
  {
    path: 'hdfs-log/:id/delete',
    component: HdfsLogDeletePopupComponent,
    resolve: {
      hdfsLog: HdfsLogResolve
    },
    data: {
      authorities: ['ROLE_USER'],
      pageTitle: 'hdfsutilApp.hdfsutilHdfsLog.home.title'
    },
    canActivate: [UserRouteAccessService],
    outlet: 'popup'
  }
];
